<!DOCTYPE>
<html>
<head>
    <base href="${config:url(pageContext.request)}">
    <title>话题管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--<meta name="_csrf_token" content="${_csrf.token}"/>-->
    <!--<meta name="_csrf_header" content="${_csrf.headerName}"/>-->
    <link href="../resources/css/backstage/list.css" type="text/css" rel="stylesheet"/>
    <link href="../resources/css/backstage/table.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" href="../resources/css/backstage/layer.css"  type="text/css" />
</head>
<body>
<div class="d-box">
    <div class="d-button">
        <input class="functionButton" type="button" onClick="javascript:window.location.href='${config:url(pageContext.request)}control/topic/list${config:suffix()}?visible=true'" value="返回">
        <input class="functionButton" type="button" onClick="javascript:window.location.href='${config:url(pageContext.request)}control/topic/manage${config:suffix()}?method=add&isTopicList=true'" value="添加话题">
        <input class="functionButton" type="button" onClick="javascript:window.location.href='${config:url(pageContext.request)}control/topic/list${config:suffix()}?visible=false'" value="回收站">
        <input class="functionButton" type="button" onClick="javascript:reductionTopic();" value="还原">
        <input class="functionButton" type="button" onClick="javascript:deleteTopic();" value="删除">
    </div>

    <table class="t-list-table" cellSpacing="1" cellPadding="0" width="100%" border="0">
        <thead class="t-list-thead">
        <tr>
            <th><input name="all" onclick="javascript:allSelect(this, 'topicId')" type="checkbox" ></th>
            <th>话题名称</th>
            <th>标签名称</th>
            <th>状态</th>
            <th>允许评论</th>
            <th>会员/员工</th>
            <th>发布时间</th>
            <th>排序</th>
            <th>操作</th>
        </tr></thead>
        <tbody class="t-list-tbody" align="center">
        <!--话题的内容-->

        <!--<c:forEach items="${pageView.records}" var="entry">-->
            <!--<TR >-->
                <!--<TD width="3%"><INPUT type="checkbox" value="${entry.id}" id="topicId_${entry.id}" name="topicId" onclick="javascript:chooseSelectBox(this);"></TD>-->
                <!--<TD width="24%">${entry.title}</TD>-->
                <!--<TD width="13%">${entry.tagName}</TD>-->
                <!--<TD width="8%"><c:if test="${entry.status == 10 || entry.status == 110}"><span style="color:red;">待审核</span></c:if><c:if test="${entry.status == 20 || entry.status == 120}">已发布</c:if></TD>-->
                <!--<TD width="8%"><c:if test="${entry.allow == true}">允许</c:if><c:if test="${entry.allow == false}"><span style="color: red;">禁止</span></c:if></TD>-->
                <!--<TD width="13%">${entry.userName}<c:if test="${entry.isStaff == true}"><span style="color: green;">[员工]</span></c:if></TD>-->
                <!--<TD width="15%"><fmt:formatDate value="${entry.postTime}" pattern="yyyy-MM-dd HH:mm:ss"/></TD>-->
                <!--<TD width="6%">${entry.sort}</TD>-->
                <!--<TD width="10%">-->
                    <!--<a href="${config:url(pageContext.request)}control/topic/manage${config:suffix()}?method=view&topicId=${entry.id}&visible=${param.visible}&topicPage=${param.page}">查看</a>-->
                    <!--<a href="#" onclick="javascript:if(window.confirm('确定删除吗? ')){document.getElementById('topicId_${entry.id}').checked =true;deleteTopic();return false;}else{return false};" hidefocus="true" ondragstart= "return false">删除</a>-->
                <!--</TD>-->
            <!--</TR>-->
        <!--</c:forEach>-->
        </tbody>
    </table>
    <!-- 分页栏开始 -->
    <div class="pg_div">
        <DIV class="pg">
            <span class="count"></span>

            <!--<A class=last href="javascript:topage('1');" title="第1页">1 ...</A>-->
            <!--当前页数-->
            <strong id="current-page"></strong>
            <!--<A class=last href="javascript:topage('${pageView.totalpage}')" title="第${pageView.totalpage}页">-->
                <!--... 1-->
            <!--</A>-->
            <label>
                <input class="pg_input" onkeydown="changPage()" type="text" value="1" size="2">
                <span id="count-page"></span>
            </label>
        </DIV>
    </div>
    <!-- 分页栏结束 -->
</div>
<script src="../resources/js/backstage/Tool.js" type="text/javascript"></script>
<script src="../resources/js/backstage/ajax.js" type="text/javascript"></script>
<script src="../resources/js/common/jquery.min.js" type="text/javascript"></script>
<script src="../resources/js/common/commonutil.js" type="text/javascript"></script>
<script src="../resources/js/backstage/topic/topiclist.js" type="text/javascript"></script>
<!-- IE6 会弹出'已终止操作'错误，本JS要放在Body标签下面 -->
<script type="text/javascript" src="../resources/js/backstage/spin.min.js" ></script>
<script type="text/javascript" src="../resources/js/backstage/layer.js" ></script>
<script type="text/javascript">


    //全选框
    function allSelect(allobj,itemName){
        var elements = document.getElementsByName(itemName);
        var state = allobj.checked;
        if(elements != null && elements.length >0){
            for(var i=0;i<elements.length;i++){
                if(!elements[i].disabled) elements[i].checked=state;
            }
        }else{
            if(!elements.disabled) elements.checked=state;
        }
    }
    //验证是否选中
    function validateIsSelect(itemName){
        var elements = document.getElementsByName(itemName);
        if(elements != null && elements.length >0){
            for(var i=0;i<elements.length;i++){
                if(elements[i].checked) return true;
            }
        }
        return false;
    }
    //选择全选框
    function chooseSelectBox(obj){
        var quantity = 0;//选中数量
        var elements = document.getElementsByName(obj.name);
        if(elements != null && elements.length >0){
            for(var i=0;i<elements.length;i++){
                if(elements[i].checked){
                    quantity++;
                }
            }
        }
        if(quantity == elements.length){
            var elements = document.getElementsByName("all");
            if(elements != null && elements.length >0){
                for(var i=0;i<elements.length;i++){
                    elements[i].checked = true;
                }
            }
        }
        if(quantity == 0 || quantity <elements.length){
            var elements = document.getElementsByName("all");
            if(elements != null && elements.length >0){
                for(var i=0;i<elements.length;i++){
                    elements[i].checked = false;
                }
            }
        }
    }


    //删除话题
    function deleteTopic(){
        if(validateIsSelect("topicId")){

            var parameter = "";
            var topicId = document.getElementsByName("topicId");
            if(topicId != null && topicId.length >0){
                for(var i=0;i<topicId.length;i++){
                    if(topicId[i].checked){
                        parameter += "&topicId="+topicId[i].value;
                    }
                }
            }
            var csrf =  getCsrf();
            parameter += "&_csrf_token="+csrf.token;
            parameter += "&_csrf_header="+csrf.header;
            //删除第一个&号,防止因为多了&号而出现警告: Parameters: Invalid chunk ignored.信息
            if(parameter.indexOf("&") == 0){
                parameter = parameter.substring(1,parameter.length);
            }
            post_request(function(value){
                if(value == "1"){
                    window.location.reload();
                }else{
                    alert("删除失败");
                }
            },
                "${config:url(pageContext.request)}control/topic/manage${config:suffix()}?method=delete&visible=${param.visible}&timestamp=" + new Date().getTime(), true,parameter);
        }else{
            alert("请选择选项");
        }
    }
    //还原话题
    function reductionTopic(){
        if(validateIsSelect("topicId")){
            var parameter = "";
            var topicId = document.getElementsByName("topicId");
            if(topicId != null && topicId.length >0){
                for(var i=0;i<topicId.length;i++){
                    if(topicId[i].checked){
                        parameter += "&topicId="+topicId[i].value;
                    }
                }
            }
            var csrf =  getCsrf();
            parameter += "&_csrf_token="+csrf.token;
            parameter += "&_csrf_header="+csrf.header;
            //删除第一个&号,防止因为多了&号而出现警告: Parameters: Invalid chunk ignored.信息
            if(parameter.indexOf("&") == 0){
                parameter = parameter.substring(1,parameter.length);
            }
            post_request(function(value){
                if(value == "1"){
                    window.location.reload();
                }else{
                    alert("还原失败");
                }
            },
                "${config:url(pageContext.request)}control/topic/manage${config:suffix()}?method=reduction&visible=${param.visible}&timestamp=" + new Date().getTime(), true,parameter);
        }else{
            alert("请选择选项");
        }
    }
</script>
</body>
</html>
